package org.sucri.floxs.mock;

import org.sucri.floxs.ext.widget.ColumnModel;
import org.sucri.floxs.ext.widget.Column;
import org.sucri.floxs.ext.widget.Grid;
import org.sucri.floxs.ext.data.*;
import org.sucri.floxs.ext.form.Form;
import org.sucri.floxs.model.ListTableModel;
import org.sucri.floxs.mock.mockData;
import org.sucri.floxs.factory.Ext_Factory;

import java.net.URI;

/**
 * Created by IntelliJ IDEA.
 * User: Wen Yu
 * Date: Jul 22, 2007
 * Time: 6:14:26 PM
 * To change this template use File | Settings | File Templates.
 */
public class mockExts
{
  public static Grid mockGridViaTableModel()
  {
    ListTableModel tm = new ListTableModel(mockData.mockFoos());
    Grid g = null;
    try
    {
      g = Ext_Factory.newGrid("test_grid", tm, new URI("/sucri?id=12"));
    }
    catch (Exception e) { e.printStackTrace(); }

    return g;
  }
  public static Form mockFormViaAnnotationModel()
  {
    Form f = null;
    try
    {
      f = Ext_Factory.newForm(mockData.mockFoo(), new URI("/sucri?id=12"));
    }
    catch (Exception e) { e.printStackTrace(); }

    return f;
  }
  public static ColumnModel mockColumnModel()
  {
    ColumnModel cm = new ColumnModel("test");
    cm.addColumn(new Column("test1", 100));
    cm.addColumn(new Column("test2", 150));
    cm.addColumn(new Column("test3", 10));

    return cm;
  }
  public static HttpProxy mockHttpProxy() throws Exception
  {
    return new HttpProxy("http://yuspace.org");
  }
  public static Reader mockJsonReader() throws Exception
  {
    Reader r  = new JsonReader(null, "my1", "totals", "123");

    r.addRecord(new Record("test1", "TEST!"));
    r.addRecord(new Record("test2", "TEST2"));
    r.addRecord(new Record("test3", "TEST3"));

    return r;
  }
  public static DataStore mockDataStore() throws Exception
  {
    DataStore ds = new DataStore("test", new URI(""));
    
    ds.setProxy(mockHttpProxy());
    //ds.setReader(mockJsonReader());

    return ds;
  }
  public static Grid mockGrid()
  {
    Grid g = null;
    try
    {
      g = new Grid("temp", mockDataStore(), mockColumnModel());

    }
    catch(Exception e) {e.printStackTrace(); }

    return g;
  }
}
